package com.aisoback.service.impl;


import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.aisoback.mapper.PostsMapper;
import com.aisoback.model.Posts;
import com.aisoback.model.dto.SavePostDTO;
import com.aisoback.model.vo.QueryPostsVO;
import com.aisoback.service.PostsService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.jsoup.internal.StringUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author qings
 * @description 针对表【posts】的数据库操作Service实现
 * @createDate 2024-10-08 14:39:31
 */
@Service
public class PostsServiceImpl extends ServiceImpl<PostsMapper, Posts>
        implements PostsService {
    @Resource
    private PostsMapper postsMapper;

    /**
     * 新增
     *
     * @param save
     * @return
     */
    @Override
    public int addPost(SavePostDTO save) {
        Posts posts = new Posts();
        BeanUtils.copyProperties(save, posts);
        return postsMapper.addPost(save);
    }

    /**
     * f分页查询
     *
     * @param queryPostsVO
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Page<Posts> getPostPage(QueryPostsVO queryPostsVO, Integer pageNum, Integer pageSize) {
        Page<Posts> page = new Page<>(pageNum, pageSize);
        String title = queryPostsVO.getTitle();
        if (StringUtil.isBlank(title)) {
            return postsMapper.selectPage(page, null);
        }
        Page<Posts> postList = postsMapper.getPostList(title, page);
        return postList;
    }
}




